package com.wise.service.cms.content.uploadresource;

import cn.hutool.core.collection.CollectionUtil;
import com.wise.entities.content.Resource;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoList;
import com.wise.summer.v1.cms.content.uploadresource.CheckUploadResource;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.List;

/**
 * @author Pitaya
 * @date 2020-01-13
 */

@Service
@SummerService
public class CheckUploadResourceService implements SummerServiceBean<CheckUploadResource> {
    @Override
    public void sum(CheckUploadResource summer) {
        SqlSelect select = SqlSelect.selec("*")
                .fromClassName(Resource.class)
                .eq(Resource._resourceName, summer.getFileName())
                .eqLang(Resource._lang);
        List<Resource> resources = DaoList.s(Resource.class, select);
        if (!CollectionUtil.isEmpty(resources)) {
            summer.setSummerResult(CollectionUtil.getFirst(resources));
        }
    }
}
